﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wicresoft.EKA.ITSM.Web.WebPortal.Models;
using System.Web.Configuration;
using System.Configuration;

namespace Wicresoft.EKA.ITSM.Web.WebPortal
{
    public static class SecurityConfig
    {
        public static void RegisterSecurity()
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration(null);//获取网站根目录下的配置文件
            ConfigurationSection appSetting = config.GetSection("appSettings");//获取appSettings配置块信息
            if (appSetting.SectionInformation.IsProtected)
            {//判断是否已经加密,如果已经加密则进行解密
                appSetting.SectionInformation.UnprotectSection();
            }
            else
            {//如果没有加密则进行加密
                appSetting.SectionInformation.ProtectSection("DataprotectionConfigurationProvider");
            }

            ConfigurationSection conSetting = config.GetSection("connectionStrings");//获取connectionStrings配置块信息
            if (conSetting.SectionInformation.IsProtected)
            {//判断是否已经加密,如果已经加密则进行解密
                conSetting.SectionInformation.UnprotectSection();
            }
            else
            {//如果没有加密则进行加密
                conSetting.SectionInformation.ProtectSection("DataprotectionConfigurationProvider");
            }
            config.Save();
        }
    }
}
